﻿using Travel.Data.Inputs;
using Travel.Data;
using Microsoft.AspNetCore.Mvc;
using Travel.API.Filters;
using Travel.Data.Consts;
using Travel.Data.Dtos;
using Travel.Service.User;

namespace Travel.API.Controller
{
    /// <summary>
    /// 菜单模块
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class MenuModuleController : BaseController
    {
        private readonly IMenuModuleService _menuModuleService;

        public MenuModuleController(IMenuModuleService menuModuleService)
        {
            _menuModuleService = menuModuleService;
        }

        /// <summary>
        /// 添加或修改菜单模块
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<int>> UpdateOrAdd([FromBody] MenuModuleInput input)
        {
            return await _menuModuleService.UpdateOrAdd(input);
        }
        /// <summary>
        /// 菜单模块查询
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<PageDto<MenuModuleDto>>> MenuButtonQuery([FromBody] MenuModuleQueryInput input)
        {
            return await _menuModuleService.MenuButtonQuery(input);
        }
        /// <summary>
        /// 根据菜单模块ID获取一条记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
       public async Task<Results<MenuModuleDto>> GetMenuModuleById(long id)
        {
            return await _menuModuleService.GetMenuModuleById(id);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="loginUserId"></param>
        /// <param name="idList"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<int>> RemoveMenuModule([FromBody]List<long> idList) { 
        
            return await _menuModuleService.RemoveMenuModule(idList.ToArray());
        }
    }
}
